<!-- 添加教师 -->
<template>
  <section class="add">
    <el-form  ref="form" :model="form" label-width="100px">
      <el-form-item label="登录名:" prop="loginName">
          <el-input v-model="form.loginName"></el-input>
      </el-form-item>
      <el-form-item label="姓名:">
          <el-input v-model="form.userName"></el-input>
      </el-form-item>
      <el-form-item label="性别:">
          <el-radio-group v-model="form.sex">
            <el-radio label="男"></el-radio>
            <el-radio label="女"></el-radio>
            <el-radio label="保密"></el-radio>
          </el-radio-group>          
      </el-form-item>
      <el-form-item label="密码:">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
       <el-form-item label="确认密码:">
        <el-input v-model="form.password"></el-input>
      </el-form-item>
       <el-form-item label="email:">
            <el-input v-model="form.email"></el-input>
      </el-form-item>
      <el-form-item label="部门:">
          <el-select v-model="form.deptId" placeholder="请选择" style="width:100%">
    <el-option 
      v-for="item in options"
      :key="item.value"
      :label="item.label"
      :value="item.value">
    </el-option>
  </el-select>
       </el-form-item>
          <el-form-item label="电话号码:">
            <el-input v-model="form.phoneNumber"></el-input>
      </el-form-item>
      <el-form-item label="微信号:">
            <el-input v-model="form.weixin"></el-input>
      </el-form-item>
      <el-form-item label="备注:">
      <el-input v-model="form.remark"></el-input>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="onSubmit()">添加</el-button>
        <el-button type="text" @click="cancel()">取消</el-button>
      </el-form-item>
    </el-form>
  </section>
</template>

<script>
export default {
  data() {
    return {
      form: { //表单数据初始化
        loginName: null,
        userName: null,
        sex: '男',
        password: null,
        email: null,
        deptId: null,
        phoneNumber: null,
        weixin: null,
        remark: null,
        role: 2
      
      },
      options: [{
        value: '10',
        label: '项目部'
      },{
         value: '20',
        label: '职业发展部'
      }],
      value: ''
    };
  },
  methods: {
    onSubmit() { //数据提交
      this.$axios({
        url: 'http://localhost:8888/user/add',
        method: 'post',
        data: {
          ...this.form
        }
      }).then(res => {
        if(res.data.code == 200) {
          this.$message({
            message: '数据添加成功',
            type: 'success'
          })
          this.$router.push({path: '/userList'})
        }
      })
    },
    cancel() { //取消按钮
      this.form = {}
    },
    
  }
};
</script>
<style lang="scss" scoped>
.add {
  padding: 0px 40px;
  width: 400px;
}
</style>

